﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HRM.Entity;
using System.Data;
using SubSonic.Schema;

namespace HRM.DAL
{
    public class EmployeeLeaveDAL: BaseDAL
    {
        public EmployeeLeave Add(EmployeeLeave item)
        {
            Repository.Add<EmployeeLeave>(item);
            return item;
        }

        public EmployeeLeave Update(EmployeeLeave item)
        {
            Repository.Update<EmployeeLeave>(item);
            return item;
        }

        public void Delete(int ID)
        {
            Repository.Delete<EmployeeLeave>(ID);
        }

        public List<EmployeeLeave> GetByEmpID(int ID)
        {
            var query = from record in Repository.All<EmployeeLeave>()
                        where record.EmpID == ID
                        select record;

            return query.ToList();
        }

        public EmployeeLeave GetByID(int ID)
        {
            return Repository.Single<EmployeeLeave>(item => item.ID == ID);
        }

        public DataSet GetEmployeeLeaves(int empID)
        {
            var sp = GetStoreProc("spGetEmployeeLeaves");
            sp.Command.AddParameter("@EmpID", empID,DbType.Int32);

            return sp.ExecuteDataSet();
        }
    }
}
